package com.igda.tihbms.controllers;

import java.util.ArrayList;

import android.content.res.Resources;
import android.graphics.Canvas;

import com.igda.tihbms.data.Craft;
import com.igda.tihbms.data.GameObject;

public class ObjectsController {

	private ArrayList<GameObject> objects;

	private Craft craft;

	private final LogicController logic;

	public ObjectsController(LogicController logic) {
		this.craft = new Craft(logic);
		this.logic = logic;
		this.objects = new ArrayList<GameObject>();
	}

	public void init(Resources resources, ImagesController imagesController) {
		this.craft.init(imagesController.getShip());
	}

	public void draw(Canvas canvas) {
		this.craft.draw(canvas);

		for (GameObject object : this.objects) {
			object.draw(canvas);
		}
	}

	public void updateCraftLocation(float posX, float posY) {
		this.craft.updateCraftLocation(posX, posY);
	}

	public void tick() {
		this.craft.tick();
		GameObject object;

		for (int i = this.objects.size() - 1; i >= 0; i--) {
			object = this.objects.get(i);

			object.tick();

			if (object.isDead()) {
				this.objects.remove(i);
			}
		}
	}

	public void addObject(GameObject object) {
		this.objects.add(object);
	}

	public float getShipWidth() {
		return this.craft.getWidth();
	}
}
